from typing import Any, Awaitable, Callable, Dict

from aiogram import BaseMiddleware, Bot
from aiogram.types import Message

from settings import settings
from utils import alert_admin, log


class IsGroupMessageMiddleware(BaseMiddleware): 
    async def __call__(
        self,
        handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]],
        event: Message,
        data: Dict[str, Any],
    ) -> Any:
        if event.from_user.id == event.chat.id:
          return await handler(event, data)
        else:
          if event.chat.id == settings.bots.notification_channel_id:
            return
          else:
            text = f"Bot used in {event.chat.title} ({event.chat.id})"
            log.warning(text)
            return
